/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Registro.java
 *
 * Created on 6/05/2009, 11:04:41 PM
 */
package gui;

import Multimedia.MediaSonido;
import conexion.RmiCliente;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
//import org.jvnet.substance.SubstanceLookAndFeel;
//import org.jvnet.substance.watermark.SubstanceImageWatermark;

/**
 *
 * @author arquitectura
 */
public class CrearPartida extends javax.swing.JFrame {

    private VerPerfilJugador pj;
    private Home gc;
    private String Usuario;
    public MediaSonido sonidoLogin;
    public MenuPartida mp;
   

    /** Creates new form Registro */
    public CrearPartida() {
        initComponents();
        xPnlFondo pnlFondo = new xPnlFondo(1);
        this.add(pnlFondo);
        this.pack();

        this.setSize(800, 625);
        this.setLocationRelativeTo(null);
    }

    public CrearPartida(Home gc, MenuPartida mpEntrada, String usuario, MediaSonido sonidoLoginEntrada) {

        sonidoLogin = sonidoLoginEntrada;
        this.mp = mpEntrada;
        this.gc = gc;
       
        initComponents();
        xPnlFondo pnlFondo = new xPnlFondo(1);
        this.add(pnlFondo);
        this.pack();

        this.gc = gc;
        this.setSize(800, 625);
        this.setLocationRelativeTo(null);
        this.Usuario = usuario;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        BTN_partida = new javax.swing.JButton();
        BTN_perfil = new javax.swing.JButton();
        BTN_estadisticas = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jtNumJugadores = new javax.swing.JTextField();
        jtNombrePartida = new javax.swing.JTextField();
        jcModalidad = new javax.swing.JComboBox();
        jbCrear = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Crear Partida");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(java.awt.Color.white);
        setMinimumSize(new java.awt.Dimension(800, 625));
        setResizable(false);
        setUndecorated(true);

        jPanel1.setOpaque(false);

        BTN_partida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mpartida.png"))); // NOI18N
        BTN_partida.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_partida.setBorderPainted(false);
        BTN_partida.setContentAreaFilled(false);
        BTN_partida.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mpartida_roll.png"))); // NOI18N
        BTN_partida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_partidaActionPerformed(evt);
            }
        });

        BTN_perfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mperfil.png"))); // NOI18N
        BTN_perfil.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_perfil.setBorderPainted(false);
        BTN_perfil.setContentAreaFilled(false);
        BTN_perfil.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mperfil_roll.png"))); // NOI18N
        BTN_perfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_perfilActionPerformed(evt);
            }
        });

        BTN_estadisticas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mestadisticas .png"))); // NOI18N
        BTN_estadisticas.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        BTN_estadisticas.setBorderPainted(false);
        BTN_estadisticas.setContentAreaFilled(false);
        BTN_estadisticas.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_mestadisticas_roll.png"))); // NOI18N
        BTN_estadisticas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTN_estadisticasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(183, Short.MAX_VALUE)
                .addComponent(BTN_partida)
                .addGap(38, 38, 38)
                .addComponent(BTN_perfil)
                .addGap(32, 32, 32)
                .addComponent(BTN_estadisticas)
                .addGap(62, 62, 62))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BTN_partida)
                    .addComponent(BTN_perfil)
                    .addComponent(BTN_estadisticas))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        jPanel2.setOpaque(false);

        jtNumJugadores.setForeground(new java.awt.Color(255, 255, 255));
        jtNumJugadores.setText("4");
        jtNumJugadores.setBorder(null);
        jtNumJugadores.setOpaque(false);

        jtNombrePartida.setForeground(new java.awt.Color(255, 255, 255));
        jtNombrePartida.setText("Nombre de Partida");
        jtNombrePartida.setBorder(null);
        jtNombrePartida.setOpaque(false);

        jcModalidad.setFont(new java.awt.Font("Tahoma", 0, 10));
        jcModalidad.setForeground(new java.awt.Color(51, 51, 51));
        jcModalidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "Modalidad1", "Modalidad2" }));
        jcModalidad.setBorder(null);
        jcModalidad.setOpaque(false);

        jbCrear.setText("Crear");
        jbCrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCrearActionPerformed(evt);
            }
        });

        jbCancelar.setText("Cancelar");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jbCrear, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbCancelar))
                    .addComponent(jcModalidad, javax.swing.GroupLayout.Alignment.LEADING, 0, 198, Short.MAX_VALUE)
                    .addComponent(jtNumJugadores)
                    .addComponent(jtNombrePartida, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(jtNombrePartida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jtNumJugadores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jcModalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCrear)
                    .addComponent(jbCancelar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(370, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(212, 212, 212))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(169, 169, 169)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents
    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
        gc.setVisible(true);
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void BTN_perfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_perfilActionPerformed
        // TODO add your handling code here:

        this.setVisible(false);
        pj = new VerPerfilJugador(Usuario, this.gc);
        JFrame.setDefaultLookAndFeelDecorated(true);

        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/VerPerfilAdmin.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));

        pj.setVisible(true);
    }//GEN-LAST:event_BTN_perfilActionPerformed

    private void BTN_estadisticasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_estadisticasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);

        //JFrame.setDefaultLookAndFeelDecorated(true);
        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/Estadisticas.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));

        Estadisticas Est = new Estadisticas(Usuario, this.gc.getRc(), this.gc);
        Est.setVisible(true);
    }//GEN-LAST:event_BTN_estadisticasActionPerformed

    private void jbCrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCrearActionPerformed
        // TODO add your handling code here:
        if(this.jcModalidad.getSelectedIndex()==0)
        {
            JOptionPane.showMessageDialog(null, "Seleccione una modaliad", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        }
        else if(this.jcModalidad.getSelectedIndex()==1)
        {
           try {
                InetAddress x = InetAddress.getLocalHost();
                gc.getRc().nuevap(this.jtNombrePartida.getText()+"        "+this.jcModalidad.getSelectedItem().toString()+"        "+this.jtNumJugadores.getText(),x.getHostAddress());
                gc.getRc().setTipoj(false);
                System.out.println(x.getHostAddress());
                 System.out.println(this.gc.getRc().Puerto().get(this.gc.getRc().Puerto().size()-1));
            } catch (UnknownHostException ex) {
                Logger.getLogger(CrearPartida.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.dispose();
            TableroM2 t = new TableroM2(sonidoLogin,this.gc);
            t.iniciar(this.gc.getRc().Puerto().get(this.gc.getRc().Puerto().size()-1));
            t.setVisible(true);
        }
        else if(this.jcModalidad.getSelectedIndex()==2)
        {
            
            try {
                InetAddress x = InetAddress.getLocalHost();
                gc.getRc().nuevap(this.jtNombrePartida.getText()+"        "+this.jcModalidad.getSelectedItem().toString()+"        "+this.jtNumJugadores.getText(),x.getHostAddress());
                gc.getRc().setTipoj(true);
                System.out.println(x.getHostAddress());
                 System.out.println(this.gc.getRc().Puerto().get(this.gc.getRc().Puerto().size()-1));
            } catch (UnknownHostException ex) {
                Logger.getLogger(CrearPartida.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.dispose();
            Tablero t = new Tablero(sonidoLogin,this.gc);
           
            t.iniciar(this.gc.getRc().Puerto().get(this.gc.getRc().Puerto().size()-1));
            t.setVisible(true);
        }

        //JFrame.setDefaultLookAndFeelDecorated(true);
        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/Tablero.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));

    }//GEN-LAST:event_jbCrearActionPerformed



    private void BTN_partidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTN_partidaActionPerformed
        // TODO add your handling code here:
      
    }//GEN-LAST:event_BTN_partidaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        //JFrame.setDefaultLookAndFeelDecorated(true);
        //SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.CremeSkin");
        //SubstanceLookAndFeel.setCurrentWatermark("org.jvnet.substance.watermark.SubstanceBinaryWatermark");//Ejemplo de aplicacion de un watermark de Substance
        //SubstanceLookAndFeel.setCurrentWatermark(new SubstanceImageWatermark("http://72.29.81.246/~imindjav/images/CrearPartida.jpg"));
        //SubstanceLookAndFeel.setImageWatermarkOpacity(new Float(1));

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CrearPartida().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTN_estadisticas;
    private javax.swing.JButton BTN_partida;
    private javax.swing.JButton BTN_perfil;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbCrear;
    private javax.swing.JComboBox jcModalidad;
    private javax.swing.JTextField jtNombrePartida;
    private javax.swing.JTextField jtNumJugadores;
    // End of variables declaration//GEN-END:variables
}
